<template>
  <j-modal
    :width="modalWidth"
    :visible="visible"
    :title="title"
    switchFullscreen
    @ok="handleSubmit"
    @cancel="close"
    style="top: 50px"
    cancelText="关闭"
  >
    <a-card :bordered="false">
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row :gutter="24">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="用户姓名">
              <a-input placeholder="请输入用户姓名" v-model="queryParam.realname"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="用户部门">
              <j-dict-select-tag v-model="queryParam.orgCode" dictCode="sys_depart,depart_name,org_code" placeholder="请选择用户部门" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="用户账号">
              <a-input placeholder="请输入用户账号" v-model="queryParam.username"></a-input>
            </a-form-item>
          </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
                <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>
      <div>
        <a-table
          ref="table"
          size="middle"
          :scroll="{ x: true }"
          bordered
          rowKey="id"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange, type: checkval }"
          class="j-table-force-nowrap1"
          @change="handleTableChange"
        >
        </a-table>
      </div>
    </a-card>
  </j-modal>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { filterObj } from '@/utils/util'
import { deleteAction, getAction, httpAction } from '@api/manage'

export default {
  name: 'SelectPickUserModal',
  mixins: [JeecgListMixin, mixinDevice],
  components: {},
  props: {
    category: {
      type: String,
    },
    modalWidth: {
      type: Number,
      required: false,
      default: 1250,
    },
    checkval: {
      type: String,
      default: 'radio',
    },
    supplierId: {
      type: String,
      required: false,
    },
  },
  data() {
    return {
      visible:false,
      title: '选择员工',
      description: '人员信息表',
      activeKey: 'on',
      ipagination: {
        current: 1,
        pageSize: 10,
        pageSizeOptions: ['10', '100', '3000'],
        showTotal: (total, range) => {
          return range[0] + '-' + range[1] + ' 共' + total + '条'
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0,
      },
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 50,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '用户账号',
          align: "center",
          width: 100,
          dataIndex: 'username'
        },
        {
          title: '用户名称',
          align: "center",
          width: 100,
          dataIndex: 'realname'
        },
        {
          title: '性别',
          align: "center",
          width: 100,
          dataIndex: 'sex_dictText'
        },
        {
          title: '电话',
          align: "center",
          width: 100,
          dataIndex: 'phone'
        },
        {
          title: '部门',
          align: "center",
          width: 150,
          dataIndex: 'orgCodeTxt'
        }
      ],
      url: {
        list: '/sys/user/pageList',
      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.loadData()
  },
  computed: {
  },
  methods: {
    close() {
      this.queryParam = {employeeCode:'',employeeName:''}
      this.selectedRowKeys = []
      this.selectionRows = []
      this.visible = false;
    },
    add() {
      this.showModal();
    },
    showModal() {
      this.dataSource = []
      this.visible = true;
      this.loadData();
    },
    handleSubmit() {
      this.getSelectRows();
      // this.searchReset(false)
      this.queryParam = {employeeCode:'',employeeName:''}
      this.onClearSelected();
      this.close();
    },
    getSelectRows() {
      let selectedRow = null;
      if(this.checkval=='radio'){
         selectedRow = this.selectionRows[0];
      }else{
         selectedRow = this.selectionRows
      }
      //传递选中的数据
      this.$emit("handlerOk", selectedRow);
    },
    onSelectChange(selectedRowKeys, selectionRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectionRows = selectionRows
    },
    modalFormOk() {
      this.loadData()
    },
    loadData() {
      var params = this.getQueryParams()
      params.status = '1'
      this.loading = true
      getAction(this.url.list, params)
        .then((res) => {
          if (res.success) {
            this.dataSource = res.result.records || res.result
            if (res.result.total) {
              this.ipagination.total = res.result.total
            } else {
              this.ipagination.total = 0
            }
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.loading = false
        })
    },
    initDictConfig() {},
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
